// components/park/list.ts
// pages/mine/mine.ts
// import { ajax } from "../../utils/request";

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    point: {
      type: Object
    },
    listData: {
      type: Array
    },
    firstId: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    listData:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleRoute(e:any) {
      let obj:any = {
        latitude: e.currentTarget.dataset.latitude,
        longitude: e.currentTarget.dataset.longitude,
        name: e.currentTarget.dataset.parkName,
        address: e.currentTarget.dataset.parkAddress
      } 
      // 唤起用户手机内地图导航app，：经纬度（必填）
      wx.openLocation({
        latitude: obj.latitude,
        longitude: obj.longitude,
        name: obj.name,
        address: obj.address
      })
    },
    handleTap(e:any) {
      this.triggerEvent("getPid",e.currentTarget.dataset.id) 
    },
    handleBook(e:WechatMiniprogram.CustomEvent) {        
      // 根据pid获取对象
      let pid = e.currentTarget.dataset.pid
      console.log("pid=====",pid);
      
      let listData = this.data.listData
      console.log("data === ",listData);
      
      let parking:any = listData.find((v:any) => v.pid == pid)
      console.log("parking == ",parking);
      
      // 跳转至预约页面
      wx.navigateTo({
        url: `/pages/book/appointment/appointment`,
        events: {
          // 测试接收从目标页面传回的参数
          get: (data:any) => {
            // console.log("accept == ",data);          
          } 
        },
        success: res => {
          // 通过 eventChannel 向被打开页面传送数据        
          res.eventChannel.emit("send",e.currentTarget.dataset),
          res.eventChannel.emit("send2",e)

        }
        
      }) 
    }
  },
  observers: {
    "point": function(val) {
      if (!val) {
        return;
      }
      // ajax("/location/distanceTopark",val).then(res => {
      //   if (res.data.code === 0) {
      //     this.setData({listData:res.data.data});
      //   }
      // })
    },
    "firstId": function(val) {
      console.log("监听firsiId==",val);
    },
    "listData": function(val) {
      console.log("监听list收到的listData",val);
      
    }
  }
})
